<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <div class="table-head">
          <div class="left">
            <Select v-model="typeSelectid" :transfer="true" @on-change="onChangeTypeSelect">
              <Option v-for="item in typeSelect" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="left">
            <Input v-model="search_title" size="default" placeholder="标题"/>
          </div>
          <div class="left-btn">
            <Button type="primary" @click="searchFun()">搜索</Button>
          </div>


          <Button type="primary" class="Button" @click="signatureShow()">电子签章</Button>
          <Button type="primary" class="Button" @click="leaveShow()">请假申请</Button>
          <Button type="primary" class="Button" @click="carShow()">用车申请</Button>
          <Button type="primary" class="Button" @click="FixedAssetsShow()">固定资产申请</Button>
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData"
                 @on-selection-change="selectionChange"></Table>
        </Row>
        <div style="margin: 10px;overflow: hidden;height: 36px;">
          <div style="float: right;">
            <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
          </div>
        </div>
      </Card>
      <!--详情-->
      <Modal v-model="showCurrentTableData" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">详情</h3>
        <Form label-position="top">
          <FormItem label="标题">
            <div class="dataDetail-div" v-text="dataDetail.title"></div>
          </FormItem>
          <FormItem label="申请时间">
            <div class="dataDetail-div" v-text="dataDetail.create_time"></div>
          </FormItem>
          <FormItem label="申请人">
            <div class="dataDetail-div" v-text="dataDetail.user ? dataDetail.user.name : ''"></div>
          </FormItem>
          <FormItem label="内容">
            <div class="dataDetail-div ck-editor-content" v-html="dataDetail.content"></div>
          </FormItem>
          <FormItem label="状态">
            <div class="dataDetail-div" v-text="dataDetail.statusTitle"></div>
          </FormItem>
          <FormItem label="审批记录">
            <div class="dataDetail-div Timeline">
              <Timeline v-if="approvalHistory.length > 0">
                <TimelineItem v-for="(el,index) in approvalHistory " :key="index"
                              :color="el.color">
                  <Icon type="ios-radio-button-on" slot="dot"></Icon>
                  <p class="time" v-text="el.time"></p>
                  <p class="content" v-text="el.title"></p>
                  <p class="content" v-text="el.state"></p>
                </TimelineItem>
              </Timeline>
            </div>
          </FormItem>
          <FormItem label="阅读状态" v-if="readList.length > 0">
            <div class="dataDetail-div padding-0">
              <Table stripe border :columns="readList_columns" :data="readList"></Table>
              <div class="readList_page_div text-align-center" v-if="readList_total > 0">
                <Page :total="readList_total" :current="readList_page" size="small" @on-change="readList_changePage"
                      show-elevator></Page>
              </div>
            </div>
          </FormItem>
        </Form>
        <div class="botton-action">
          <div class="comments" @click="commentsFun(dataDetail.id)">
            <Icon type="ios-text"/>
            <span v-if="dataDetail.show_comments_list != true">
              评论（{{dataDetail.subject && dataDetail.subject.reply && dataDetail.subject.reply.reply_number > 0 ? dataDetail.subject.reply.reply_number : 0}}）
            </span>
            <span v-if="dataDetail.show_comments_list == true">收起评论</span>
          </div>
        </div>
        <div class="comments-list comments-list-div" v-if="dataDetail.show_comments_list == true">
          <comments-list
            reply_type="approval"
            :reply_type_id="dataDetail.id"
          ></comments-list>
        </div>
        <div slot="footer">
          <Button type="text" @click="hideDetailModal">取消</Button>
          <!--<Button type="success" v-if="approval_type_id == 6 && approval_stage == 2 && approval_status == 'checking'"
                  @click="showNextApprover()">指派下一步审批人
          </Button>-->
          <Button type="success" v-if="approval_type_id == 6 && approval_stage == 2 && approval_status == 'checking'"
                  @click="showAssets()">固定资产分配
          </Button>
          <Button type="error" :loading="rejectedLoading" v-if="typeSelectid == 'approving'"
                  @click="rejectedApproval()">驳回
          </Button>
          <Button type="primary" :loading="passLoading" v-if="typeSelectid == 'approving'"
                  @click="passApproval()">
            通过
          </Button>
        </div>
      </Modal>
      <!--电子签章-->
      <Modal v-model="signatureDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">电子签章</h3>
        <Form label-position="top">
          <FormItem label="审批人">
            <Select v-model="signatureData.approvers" :transfer="true" style="width:100%;">
              <Option v-for="item in approversArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="附件（pdf）">
            <div class="dataDetail-div chooseUser accessory">
              <div class="users" v-for="el in signatureData.accessory">
                <span class="span-name" v-text="el.name"></span>
                <span class="span-icon" @click="delAccessory(el)">
                  <Icon type="close-round"></Icon>
                </span>
              </div>
              <Upload v-if="signatureData.accessory.length == 0"
                      :before-upload="handleUpload" action="">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
          <FormItem label="签章位置">
            <Input v-model="signatureData.sign_key" placeholder="签章位置"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="signatureSave()">确定</Button>
        </div>
      </Modal>
      <!--请假-->
      <Modal v-model="leaveDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">请假申请</h3>
        <Form label-position="top">
          <FormItem label="请假事由">
            <Input v-model="leaveData.reason" placeholder="请假事由"></Input>
          </FormItem>
          <FormItem label="请假类型">
            <Select v-model="leaveData.tid" :transfer="true" style="width:100%;">
              <Option v-for="item in leaveTypeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="请假时间">
            <DatePicker type="datetimerange"
                        format="yyyy-MM-dd HH:mm:ss"
                        :confirm="true"
                        :transfer="true"
                        :editable="false"
                        placement="bottom-start"
                        placeholder="请选择请假时间"
                        v-model="leaveData.DatePickerValue"
                        style="width: 100%;"></DatePicker>
          </FormItem>
          <FormItem label="审批人">
            <Select v-model="leaveData.approvers" :transfer="true" style="width:100%;">
              <Option v-for="item in approversArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="知会人">
            <div class="dataDetail-div">
              <Tree ref="leave_tree" :data="TreeData" show-checkbox multiple></Tree>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="leaveSave()">确定</Button>
        </div>
      </Modal>
      <!--用车-->
      <Modal v-model="carDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">用车申请</h3>
        <Form label-position="top">
          <FormItem label="用车理由">
            <Input v-model="carData.reason" placeholder="用车理由"></Input>
          </FormItem>
          <FormItem label="用车人数">
            <InputNumber :max="100" :min="1" v-model="carData.number" class="InputNumber"></InputNumber>
          </FormItem>
          <FormItem label="选择车型">
            <Select v-model="carData.carType" :transfer="true" @on-change="getCar" style="width:100%;">
              <Option v-for="item in carData.carTypeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="选择车">
            <Select v-model="carData.car" :transfer="true" style="width:100%;">
              <Option v-for="item in carData.carArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="用车时间">
            <DatePicker type="datetimerange"
                        format="yyyy-MM-dd HH:mm:ss"
                        :confirm="true"
                        :transfer="true"
                        :editable="false"
                        placement="bottom-start"
                        placeholder="请选择用车时间"
                        v-model="carData.DatePickerValue"
                        style="width: 100%;"></DatePicker>
          </FormItem>
          <FormItem label="审批人">
            <Select v-model="carData.approvers" :transfer="true" style="width:100%;">
              <Option v-for="item in approversArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="知会人">
            <div class="dataDetail-div">
              <Tree ref="car_tree" :data="TreeData" show-checkbox multiple></Tree>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="carSave()">确定</Button>
        </div>
      </Modal>
      <!--固定资产-->
      <Modal v-model="FixedAssetsDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">固定资产申请</h3>
        <Form label-position="top">
          <FormItem label="物品名">
            <Select v-model="FixedAssetsData.type_id" :transfer="true" style="width:100%;">
              <Option v-for="item in FixedAssetsData.typeArr" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </FormItem>
          <FormItem label="个数">
            <InputNumber :max="1000" :min="1" v-model="FixedAssetsData.number" class="InputNumber"></InputNumber>
          </FormItem>
          <FormItem label="申请说明">
            <Input v-model="FixedAssetsData.description" type="textarea" class="textarea_resize"
                   :autosize="{minRows: 3}" placeholder="申请说明"></Input>
          </FormItem>
          <FormItem label="审批人">
            <Select v-model="FixedAssetsData.approvers" :transfer="true" style="width:100%;">
              <Option v-for="item in approversArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="知会人">
            <div class="dataDetail-div">
              <Tree ref="FixedAssets_tree" :data="TreeData" show-checkbox multiple></Tree>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="FixedAssetsSave()">确定</Button>
        </div>
      </Modal>
      <!--指派下一步审批人-->
      <Modal v-model="NextApproverModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">指派下一步审批人</h3>
        <Form label-position="top">
          <FormItem label="审批人">
            <Select v-model="leaveData.approvers" :transfer="true" style="width:100%;">
              <Option v-for="item in approversArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
          <FormItem label="知会人">
            <div class="dataDetail-div">
              <Tree ref="leave_tree" :data="TreeData" show-checkbox multiple></Tree>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="leaveSave()">确定</Button>
        </div>
      </Modal>
      <!--固定资产分配-->
      <Modal v-model="AssetsModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">固定资产分配</h3>
        <Form label-position="top">
          <FormItem label="待分配物品">
            <Table stripe border class="margin-top-8" @on-selection-change="selectionChangeAssets"
                   :columns="AssetsList_columns" :data="AssetsListData"></Table>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAssets">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveAssets()">确定</Button>
        </div>
      </Modal>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  import commentsList from '../components/comments-list.vue';
  export default {
    components: {
      commentsList
    },
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        readList_total: 0,
        readList_page: 1,
        id: '',
        approval_type_id: '',
        approval_stage: '',
        approval_status: '',
        typeSelectid: 'approving',
        typeSelect: [
          {
            id: 'apply',
            name: '我申请的',
          },
          {
            id: 'approving',
            name: '待我审批的',
          },
          {
            id: 'approved',
            name: '我已审批的',
          },
          {
            id: 'informed',
            name: '知会我的',
          },
        ],
        search_title: '',// 搜索 标题
        show_comments_list: false,// 评论
        show_users: '',
        searchConName: '',
        searchConTel: '',
        showCurrentTableData: false,
        loading: true,
        showCurrentColumns: [],
        editInlineAndCellData: [],
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'name',
            title: '申请人',
          },
          {
            key: 'title',
            title: '标题',
          },
          {
            key: 'status',
            title: '状态',
            render: (h, params) => {
              var status = params.row.status;
              if (status == 'checking') {
                status = '待审批';
              } else if (status == 'passed') {
                status = '已通过';
              } else if (status == 'rejected') {
                status = '已驳回';
              }
              return h('div', [
                h('span', status)
              ]);
            }
          },
          {
            key: 'create_time',
            title: '创建时间',
            width: 160
          },
        ],
        data: [],
        dataDetail: {},
        approvalHistory: [],
        initTable: [],
        saveLoading: false,
        rejectedLoading: false,
        passLoading: false,
        ajaxType: 'add',
        signatureDataModal: false,
        leaveDataModal: false,
        carDataModal: false,
        FixedAssetsDataModal: false,
        signatureData: {
          approvers: '',
          sign_key: '',
          accessory: [],
        },
        leaveData: {
          reason: '',
          tid: '',
          DatePickerValue: [],
          approvers: '',
        },
        carData: {
          reason: '',
          number: 1,
          carType: '',
          car: '',
          DatePickerValue: [],
          approvers: '',
          carTypeArr: [],
          carArr: [],
        },
        FixedAssetsData: {
          description: '',
          type_id: '',
          number: 1,
          approvers: '',
          typeArr: [],
        },
        selectionArr: [],
        approversArr: [],
        leaveTypeArr: [],
        TreeData: [],
        checked_dep_arr: [],
        checked_users_arr: [],
        editor: null,
        NextApproverModal: false,
        AssetsModal: false,
        AssetsData: {},
        AssetsListData: [],
        selectionAssetsArr: [],
        AssetsList_columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'type',
            title: '物品名',
            render: (h, params) => {
              var type = params.row.type;
              var title = type.title;
              return h('div', [
                h('span', title)
              ]);
            }
          },
          {
            key: 'asset_number',
            title: '物品编号',
          },
        ],
        readList: [],
        readList_columns: [
          {
            key: 'name',
            title: '姓名',
          },
          {
            key: 'status',
            title: '阅读状态',
            render: (h, params) => {
              return h('div', [
                h('span', params.row.status == true ? '已读' : '未读')
              ]);
            }
          },
          {
            key: 'read_time',
            title: '阅读时间',
          },
        ],
      };
    },
    created: function () {
      var _this = this;
      // 首页 仪表盘过来的
      var approval_type = localStorage.getItem('approval_type');
      if (approval_type && approval_type != '') {
        _this.typeSelectid = approval_type;
        localStorage.removeItem('approval_type');
      }
      _this.getData();
    },
    mounted () {
    },
    methods: {
      onChangeTypeSelect: function (val) {
        var _this = this;
        _this.typeSelectid = val;
        _this.page = 1;
        _this.getData();
      },
      // 搜索
      searchFun: function () {
        var _this = this;
        _this.page = 1;
        _this.getData();
      },
      // 评论
      commentsFun: function (id) {
        var _this = this;
        if (_this.dataDetail.show_comments_list) {
          _this.dataDetail.show_comments_list = false;
        } else {
          _this.dataDetail.show_comments_list = true;
        }
      },
      getData () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          filter: _this.typeSelectid,
          page: _this.page,
          size: _this.size,
          title: _this.search_title,
        };
        var params = {
          url: '/approval/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.total = res.rows;
            _this.data = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      changePage (page) {
        var _this = this;
        _this.page = page;
        _this.getData();
      },
      onRowData: function (data, index) {
        var _this = this;
        _this.show(index, data);
      },
      show: function (index, data) {
        var _this = this;
        var id = data.id;
        _this.id = id;
        _this.readUpdate();//更新已读
        var data = {
          id: _this.id,
        };
        var params = {
          url: '/approval/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.AssetsData = _data.data ? _data.data : {};
            var statusTitle = _data.status;
            if (statusTitle == 'checking') {
              statusTitle = '待审批';
            } else if (statusTitle == 'passed') {
              statusTitle = '已通过';
            } else if (statusTitle == 'rejected') {
              statusTitle = '已驳回';
            }
            _data.statusTitle = statusTitle;

            var type_id = _data.type.id;
            var user = _data.user;
            var userid = user.id;
            var realName = user.name;

            var stage = _data.stage;
            var total_stage = _data.total;
            var process = _data.process;
            var approvalHistory = [];
            var obj = {
              status: 'passed',
              title: realName + '提交了该审批',
              state: '',
              time: _data.create_time,
              color: 'green',
            };
            approvalHistory.push(obj);
            for (var i = 1; i <= total_stage; i++) {
              if (!process['stage' + i]) {
                continue;
              }
              var tem = process['stage' + i];
              var approver = tem.approvers;
              var approverUsers = [];
              var stateArr = [];
              var title = '';
              var state = '';
              var time = '';
              for (var k in approver) {
                var uname = approver[k].name;
                approverUsers.push(uname);
                var status = approver[k].status;
                if (status == 'passed') {
                  stateArr.push(uname + '通过了该审批;');
                } else if (status == 'rejected') {
                  stateArr.push(uname + '驳回了该审批;');
                }
                time = approver[k].last_modify_time;
              }
              title = '审批人：' + approverUsers.join(',');
              state = stateArr.join('<br>');
              if (i > _this.stage) {
                state = '';
              }
              var color = '#bbbec4';
              var result = tem.result;
              if (result == 'passed') {
                color = 'green';
              } else if (result == 'rejected') {
                color = 'red';
              }
              var obj = {
                status: tem.result,
                title: title,
                state: state,
                time: time,
                color: color,
              };
              approvalHistory.push(obj);
            }
            _data.show_comments_list = false;
            _this.approval_type_id = type_id;
            _this.approval_stage = stage;
            _this.approval_status = _data.status;// checking 待审核; passed 已通过; rejected 已驳回;
            _this.approvalHistory = approvalHistory;
            _this.dataDetail = _data;
            _this.showCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 已读未读,分页条
      readList_changePage: function (page) {
        var _this = this;
        _this.readList_page = page;
        _this.getReadList();
      },
      // 更新已读
      readUpdate: function () {
        var _this = this;
        var data = {
          tid: _this.id,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'approval',
        };
        var params = {
          url: '/read/status/update',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {

          } else {

          }
          _this.getReadList();
        }
      },
      // 查看已读列表
      getReadList: function () {
        var _this = this;
        var data = {
          tid: _this.id,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'approval',
          page: _this.readList_page,
          size: _this.size,
        };
        var params = {
          url: '/read/status/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.readList_total = res.rows || 0;
            _this.readList = res.data ? res.data : [];
          } else {
            _this.$Message.error('查询已读人员列表失败!');
          }
        }
      },
      hideDetailModal: function () {
        var _this = this;
        _this.showCurrentTableData = false;
      },
      // 审批通过
      passApproval: function () {
        var _this = this;
        var type_id = _this.dataDetail.type.id;
        // type_id 1.自定义 2.入职 3.请假 4.公告 5.用车 6.固定资产 7.办公用品 8.电子签章
        if (type_id == 8) {
          _this.$Message.error('电子签章业务，请在手机端审核!');
          return false;
        }
        var data = {
          id: _this.id,
          pass: true,
        };
        var params = {
          url: '/approval/update',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.passLoading = true;
        function _successFun(res) {
          _this.passLoading = false;
          if (res.result == 0) {
            _this.getData();
            _this.hideDetailModal();
            _this.$Message.success('审核成功!');
          } else {
            _this.$Message.error('审核失败!');
          }
        }
      },
      // 审批驳回
      rejectedApproval: function () {
        var _this = this;
        var type_id = _this.dataDetail.type.id;
        // type_id 1.自定义 2.入职 3.请假 4.公告 5.用车 6.固定资产 7.办公用品 8.电子签章
        if (type_id == 8) {
          _this.$Message.error('电子签章业务，请在手机端审核!');
          return false;
        }
        var data = {
          id: _this.id,
          pass: false,
        };
        var params = {
          url: '/approval/update',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.rejectedLoading = true;
        function _successFun(res) {
          _this.rejectedLoading = false;
          if (res.result == 0) {
            _this.getData();
            _this.hideDetailModal();
            _this.$Message.success('审核成功!');
          } else {
            _this.$Message.error('审核失败!');
          }
        }
      },
      // 显示修改下一步审批人
      showNextApprover: function () {
        var _this = this;
        _this.hideDetailModal();
        _this.NextApproverModal = true;
      },
      // 隐藏修改下一步审批人
      hideNextApprover: function () {
        var _this = this;
      },
      // 修改下一步审批人
      updateNextApprover: function () {
        var _this = this;
      },
      // 显示固定资产分配
      showAssets: function () {
        var _this = this;
        var AssetsData = _this.AssetsData;
        var type_id = AssetsData.type_id ? AssetsData.type_id : '';
        if (type_id == '') {
          _this.$Message.error('查询资产信息错误!');
          _this.hideAssets();
          return false;
        }
        var data = {
          type_id: type_id,
          hold: 0, // 0无人持有，1有人持有，2全部
          page: 1,
          size: 20,
        };
        var params = {
          url: '/asset/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.AssetsListData = _data;
            _this.selectionAssetsArr = [];

            _this.hideDetailModal();
            _this.AssetsModal = true;
          } else {
            _this.$Message.error('查询资产信息失败!');
          }
        }
      },
      // 隐藏固定资产分配
      hideAssets: function () {
        var _this = this;
        _this.AssetsModal = false;
      },
      // 固定资产列表多选 选中数据
      selectionChangeAssets: function (selection) {
        var _this = this;
        _this.selectionAssetsArr = selection;
      },
      // 固定资产分配
      saveAssets: function () {
        var _this = this;
        var selectionAssetsArr = _this.selectionAssetsArr;
        console.log('selectionAssetsArr', selectionAssetsArr);
        if (selectionAssetsArr.length == 0) {
          _this.$Message.error('请选择要分配的物品!');
          return false;
        }
        var asset_id = [];
        for (var k in selectionAssetsArr) {
          if (!selectionAssetsArr[k]) {
            continue;
          }
          var id = selectionAssetsArr[k].id;
          asset_id.push(id);
        }
        var data = {
          aid: _this.id,
          asset_id: asset_id,
        };
        var params = {
          url: '/asset/distribution',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.hideAssets();
            _this.$Message.success('分配固定资产成功!');
          } else {
            _this.$Message.error('分配固定资产失败!');
          }
        }
      },
      // 获取审批人
      getApproversArr: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/approval/leader',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.approversArr = _data.approvers;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 获取请假类型
      getleaveTypeArr: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/approval/vacation/type',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.leaveTypeArr = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 获取物品名
      getFixedAssetsTypeArr: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/asset/type/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.FixedAssetsData.typeArr = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 选中文件
      handleUpload: function (file) {
        var _this = this;
        _this.UploadFile(file);
        return false;
      },
      // 上传文件
      UploadFile: function (file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var type = arr[arr.length - 1];
        if (type != 'pdf' && type != 'PDF') {
          _this.$Message.error('请上传pdf文件!');
          return false;
        }
        var formData = new FormData();
        formData.append("file", file);
        formData.append("action", "UploadVMKImagePath");
        var params = {
          url: '/file/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var name = data.name;
            var url = data.url;
            var obj = {
              id: id,
              name: name,
              url: url,
            };
            _this.signatureData.accessory.push(obj);
          } else {
            _this.$Message.error('上传失败!');
          }
        }
      },
      // 删除附件
      delAccessory: function (el) {
        var _this = this;
        var id = el.id;
        var accessory = _this.signatureData.accessory;
        for (var k in accessory) {
          if (!accessory[k]) {
            continue;
          }
          if (id == accessory[k].id) {
            var del = accessory.splice(k, 1);
            break;
          }
        }
        _this.signatureData.accessory = accessory;
      },
      // 获取选人 树信息
      getTreeData: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          id: 1
        };
        var params = {
          url: '/department/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var TreeData = [];
            TreeData.push(data);
            _this.toDataFun(TreeData);
            _this.TreeData = TreeData;
          } else {
            _this.$Message.error('查询人员信息失败!');
          }
        }
      },
      // 处理树信息
      toDataFun: function (arr) {
        var _this = this;
        arr.forEach(function (e) {
          e.title = e.name;
          e.expand = true;//展开
          if (e.type) {
            e.type = 'dep';
            var checked_dep_arr = _this.checked_dep_arr;
            if (Utils.idInArray(e.id, checked_dep_arr)) {
              e.checked = true;// 选中
            }
          } else {
            e.type = 'user';
            var checked_users_arr = _this.checked_users_arr;
            if (Utils.idInArray(e.id, checked_users_arr)) {
              e.checked = true;// 选中
            }
          }
          var staff = e.staff || [];
          var children = e.children || [];
          if (children.length == 0) {
            e.children = [];
          }
          e.children.push(...staff);
          _this.toDataFun(e.children);
        });
      },
      // 列表多选 选中数据
      selectionChange: function (selection) {
        var _this = this;
        _this.selectionArr = selection;
      },
      // 获取用车类型
      getcarType: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/approval/car/type',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.carData.carTypeArr = _data;
            if (_data.length > 0) {
              var id = _data[0].id;
              _this.getCar(id);
            }
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 获取用车
      getCar: function (id) {
        var _this = this;
        var data = {
          tid: id
        };
        var params = {
          url: '/approval/car/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.carData.carArr = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 隐藏编辑页面
      hideAddModal: function () {
        var _this = this;
        _this.signatureDataModal = false;
        _this.leaveDataModal = false;
        _this.carDataModal = false;
        _this.FixedAssetsDataModal = false;
      },
      // 显示电子签章
      signatureShow: function () {
        var _this = this;
        _this.signatureData.approvers = '';
        _this.signatureData.sign_key = '';
        _this.signatureData.accessory = [];
        _this.getApproversArr();
        _this.signatureDataModal = true;
      },
      // 保存电子签章
      signatureSave: function () {
        var _this = this;
        var approvers = _this.signatureData.approvers;
        var sign_key = _this.signatureData.sign_key;
        var accessory = _this.signatureData.accessory;

        if (!(approvers && approvers != '')) {
          _this.$Message.error('请选择审批人!');
          return false;
        }
        if (accessory.length == 0) {
          _this.$Message.error('请上传文件!');
          return false;
        }
        if (sign_key == '') {
          _this.$Message.error('请填写签章位置!');
          return false;
        }
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          file_id: accessory[0].id,
          approvers: [approvers],
          sign_key: sign_key,
        };
        var params = {
          url: '/vender/linksign/add',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.signatureData.approvers = '';
            _this.signatureData.sign_key = '';
            _this.signatureData.accessory = [];

            _this.hideAddModal();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 显示请假
      leaveShow: function () {
        var _this = this;
        _this.leaveData.reason = '';
        _this.leaveData.tid = '';
        _this.leaveData.DatePickerValue = [];
        _this.leaveData.approvers = '';
        _this.TreeData = [];
        _this.getApproversArr();
        _this.getleaveTypeArr();
        _this.getTreeData();
        _this.leaveDataModal = true;
      },
      // 保存请假
      leaveSave: function () {
        var _this = this;
        var reason = _this.leaveData.reason;
        var tid = _this.leaveData.tid;
        var DatePickerValue = _this.leaveData.DatePickerValue;
        var approvers = _this.leaveData.approvers;
        var CheckedNodes = _this.$refs.leave_tree.getCheckedNodes();

        if (reason == '') {
          _this.$Message.error('请填写请假事由!');
          return false;
        }
        if (tid == '') {
          _this.$Message.error('请选择请假事由!');
          return false;
        }
        if (DatePickerValue.length == 0) {
          _this.$Message.error('请选择请假时间!');
          return false;
        }
        if (approvers == '') {
          _this.$Message.error('请选择审批人!');
          return false;
        }
        var startDateVal = DatePickerValue[0];
        var endDateVal = DatePickerValue[1];
        var startDate = Utils.timestampToFormatDatetime(startDateVal);
        var endDate = Utils.timestampToFormatDatetime(endDateVal);
        var departments = [];
        var users = [];
        for (var k in CheckedNodes) {
          if (!CheckedNodes[k]) {
            continue;
          }
          var id = CheckedNodes[k].id;
          var type = CheckedNodes[k].type;
          if (type == 'dep') {
            departments.push(id);
          } else if (type == 'user') {
            users.push(id);
          }
        }
        var data = {
          reason: reason,
          tid: tid,
          start_time: startDate,
          end_time: endDate,
          approvers: [approvers],
          inform: {
            users: users,
            departments: departments
          }
        };
        var params = {
          url: '/approval/vacation/add',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.leaveData.reason = '';
            _this.leaveData.tid = '';
            _this.leaveData.DatePickerValue = [];
            _this.leaveData.approvers = '';

            _this.hideAddModal();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 显示用车
      carShow: function () {
        var _this = this;
        _this.carData.reason = '';
        _this.carData.number = 1;
        _this.carData.carType = '';
        _this.carData.car = '';
        _this.carData.DatePickerValue = [];
        _this.carData.approvers = '';
        _this.TreeData = [];
        _this.getApproversArr();
        _this.getcarType();
        _this.getTreeData();
        _this.carDataModal = true;
      },
      // 保存用车
      carSave: function () {
        var _this = this;
        var reason = _this.carData.reason;
        var number = _this.carData.number;
        var car = _this.carData.car;
        var DatePickerValue = _this.carData.DatePickerValue;
        var approvers = _this.carData.approvers;
        var CheckedNodes = _this.$refs.car_tree.getCheckedNodes();
        if (reason == '') {
          _this.$Message.error('请填写用车理由!');
          return false;
        }
        if (car == '') {
          _this.$Message.error('请选择车!');
          return false;
        }
        if (DatePickerValue.length == 0) {
          _this.$Message.error('请选择用车时间!');
          return false;
        }
        if (approvers == '') {
          _this.$Message.error('请选择审批人!');
          return false;
        }
        var startDateVal = DatePickerValue[0];
        var endDateVal = DatePickerValue[1];
        var startDate = Utils.timestampToFormatDatetime(startDateVal);
        var endDate = Utils.timestampToFormatDatetime(endDateVal);
        var departments = [];
        var users = [];
        for (var k in CheckedNodes) {
          if (!CheckedNodes[k]) {
            continue;
          }
          var id = CheckedNodes[k].id;
          var type = CheckedNodes[k].type;
          if (type == 'dep') {
            departments.push(id);
          } else if (type == 'user') {
            users.push(id);
          }
        }
        var data = {
          "reason": reason,
          "number": number,
          "car": car,
          "start_time": startDate,
          "end_time": endDate,
          "approvers": [approvers],
          "inform": {
            "users": users,
            "departments": departments
          }
        };
        var params = {
          url: '/approval/car/add',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.carData.reason = '';
            _this.carData.number = 1;
            _this.carData.carType = '';
            _this.carData.car = '';
            _this.carData.DatePickerValue = [];
            _this.carData.approvers = '';

            _this.hideAddModal();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 显示固定资产
      FixedAssetsShow: function () {
        var _this = this;
        _this.FixedAssetsData.description = '';
        _this.FixedAssetsData.number = 1;
        _this.FixedAssetsData.type_id = '';
        _this.FixedAssetsData.approvers = '';
        _this.TreeData = [];
        _this.getApproversArr();
        _this.getFixedAssetsTypeArr();
        _this.getTreeData();
        _this.FixedAssetsDataModal = true;
      },
      // 保存固定资产
      FixedAssetsSave: function () {
        var _this = this;
        var description = _this.FixedAssetsData.description;
        var number = _this.FixedAssetsData.number;
        var type_id = _this.FixedAssetsData.type_id;
        var approvers = _this.FixedAssetsData.approvers;
        var CheckedNodes = _this.$refs.FixedAssets_tree.getCheckedNodes();
        if (type_id == '') {
          _this.$Message.error('请选择物品名!');
          return false;
        }
        if (description == '') {
          _this.$Message.error('请填写申请说明!');
          return false;
        }
        if (approvers == '') {
          _this.$Message.error('请选择审批人!');
          return false;
        }
        var departments = [];
        var users = [];
        for (var k in CheckedNodes) {
          if (!CheckedNodes[k]) {
            continue;
          }
          var id = CheckedNodes[k].id;
          var type = CheckedNodes[k].type;
          if (type == 'dep') {
            departments.push(id);
          } else if (type == 'user') {
            users.push(id);
          }
        }
        var data = {
          description: description,
          type_id: type_id,
          number: number,
          approvers: [approvers],
          inform: {
            users: users,
            departments: departments
          }
        };
        var params = {
          url: '/asset/personal/apply',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.FixedAssetsData.description = '';
            _this.FixedAssetsData.number = 1;
            _this.FixedAssetsData.type_id = '';
            _this.FixedAssetsData.approvers = '';

            _this.hideAddModal();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 导出
      ExportData: function () {
        var _this = this;

      },
    }
  };
</script>
